package com.lzy.controller;

import com.lzy.pojo.netty.ChatMsg;
import com.lzy.rabbitmq.RabbitMQTestConfig;
import com.lzy.utils.JsonUtils;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("h")
public class helloController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("mq")
    public Object mq(){
        ChatMsg chatMsg = new ChatMsg();
        chatMsg.setMsg("hello mq");
        String msg = JsonUtils.objectToJson(chatMsg);
        rabbitTemplate.convertAndSend(RabbitMQTestConfig.EXCHANGE_NAME,
                                      RabbitMQTestConfig.ROUTING_KEY_TEST_SEND,
                                        msg);
        return "ok";
    }
}
